﻿using GameCreator.Camera;
using GameCreator.Core.Hooks;
using GameCreator.Messages;
using Gp.Scripts.Core;
using QFramework;
using UnityEngine;

namespace Gp.Scripts.Core.Command {
    public class ExitDetailModeCommand : AbstractCommand {
        private readonly float _transitionTime = 0.2f;

        public ExitDetailModeCommand(float transitionTime) {
            this._transitionTime = transitionTime;
        }

        public ExitDetailModeCommand() { }


        protected override void OnExecute() {
            // // 更换为主摄像机
            // this.SendCommand(new ChangeCameraMotorCommand());
            //
            // // 返回Play层
            // InputLayerSystem.Instance.SwitchLayer(InputLayer.Play);
        }
    }


    public class ChangeCameraMotorCommand : AbstractCommand {
        private readonly CameraMotor _cameraMotor;
        private readonly float _transitionTime;

        public ChangeCameraMotorCommand(CameraMotor cameraMotor, float transitionTime = 0.2f) {
            _cameraMotor = cameraMotor == null ? CameraMotor.MAIN_MOTOR : cameraMotor;
            _transitionTime = transitionTime;
        }
        
        
        public ChangeCameraMotorCommand(float transitionTime = 0.2f) {
            _cameraMotor = CameraMotor.MAIN_MOTOR;
            _transitionTime = transitionTime;
        }


        public ChangeCameraMotorCommand() {
            _cameraMotor = CameraMotor.MAIN_MOTOR;
            _transitionTime = .2f;
        }

        protected override void OnExecute() {
            if (HookCamera.Instance == null) return;
            CameraController cameraController = HookCamera.Instance.Get<CameraController>();
            if (cameraController == null || _cameraMotor == null) return;


            if (_cameraMotor == CameraMotor.MAIN_MOTOR) {
                // 设置延迟
                cameraController.cameraSmoothTime.positionDuration = .1f;
                cameraController.cameraSmoothTime.rotationDuration = .1f;
            }
            // else {
            //     cameraController.cameraSmoothTime.positionDuration = 0;
            //     cameraController.cameraSmoothTime.rotationDuration = 0;
            // }

            cameraController.ChangeCameraMotor(
                _cameraMotor,
                this._transitionTime
            );
        }
    }
}